#pragma once

#include <iostream>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <vector>

/*========================================<网络地址类>========================================*/

class InetAddress
{
public:
    struct sockaddr_in addr;
    socklen_t addr_len;
    InetAddress();
    InetAddress(const char* ip, uint16_t port);
    ~InetAddress();
};

/*========================================<socket套接字类>========================================*/

class Socket
{
private:
    int fd;
public:
    Socket();
    Socket(int fd);
    ~Socket();

    int getFd()const;
    
    void setnonblocking();
    
    void bind(InetAddress* ServerInetAddr);
    void listen(int backLog);
    int accept(InetAddress* clientInetAddr);
};

/*========================================<epoll边缘触发类，IO多路复用>========================================*/

#define MAX_EVENTS 1024

class EpollET
{
private:
    int epfd;
    struct epoll_event* events;
public:
    EpollET();
    ~EpollET();

    int add_fd(int fd, uint32_t op);
    std::vector<epoll_event> poll(int timeout = -1);
};